package studiodiva.portfolio.client.view.pages;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

import java.util.Iterator;

import studiodiva.portfolio.client.lib.view.View;
import studiodiva.portfolio.client.model.titles.Page;

public class PageView extends View<FlowPanel> implements HasWidgets {

  interface Binder extends UiBinder<FlowPanel, PageView> {}

  static Binder uiBinder = GWT.create(Binder.class);

  @UiField(provided = true)
  ImageResource image;
  @UiField(provided = true)
  String text;
  @UiField(provided = true)
  String title;

  @UiConstructor
  public PageView(Page page) {
    super.initialize(page);
    text = page.getText();
    title = page.getTitle();
    image = page.getImage();
    initWidget(uiBinder.createAndBindUi(this));
  }

  public void add(IsWidget w) {
    add(w.asWidget());
  }

  public void add(Widget w) {
    widget().add(w);
  }

  public void clear() {
    widget().clear();
  }

  public Iterator<Widget> iterator() {
    return widget().iterator();
  }

  public boolean remove(Widget w) {
    return widget().remove(w);
  }
}
